(fix) cqlengine: handle missing table metadata after schema change in sync_table#11
Open
mykaul wants to merge 2 commits into
Open
(fix) cqlengine: handle missing table metadata after schema change in sync_table#11mykaul wants to merge 2 commits into
mykaul wants to merge 2 commits into
Conversation
d937ce8 to
6f1be93
Compare
… sync_table After CREATE TABLE or ALTER TABLE, the local metadata cache may not yet contain the new table if schema agreement timed out or the automatic metadata refresh was skipped. _sync_table() and _get_table_metadata() unconditionally accessed cluster.metadata.keyspaces[ks].tables[table], which raised KeyError in this case. Wrap both lookups in try/except KeyError. On miss, force a targeted cluster.refresh_table_metadata() call and retry once. If the table is still not present after the forced refresh, raise a descriptive CQLEngineException instead of a bare KeyError. This follows the same defensive pattern already used in _sync_type(), which calls cluster.refresh_user_type_metadata() after CREATE TYPE. Add unit tests for _get_table_metadata verifying: immediate hit (no refresh), successful retry after refresh, and failure after refresh.
6f1be93 to
d5c3f18
Compare
Drop the detailed description from the test_management.py docstring, keeping only the general module-level summary.
30a8fd7 to
59408e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_sync_table()and_get_table_metadata()withtry/except KeyError, forcing a targetedcluster.refresh_table_metadata()on miss and retrying onceCQLEngineException(instead of a bareKeyError) if the table is still not present after the forced refresh_sync_type()(which callscluster.refresh_user_type_metadata()after CREATE TYPE)Root cause
After
CREATE TABLEorALTER TABLE, the local metadata cache may not yet contain the new table if schema agreement timed out or the automatic metadata refresh was skipped. Both_sync_table()(line 273) and_get_table_metadata()(line 435) unconditionally accessedcluster.metadata.keyspaces[ks].tables[table], which raisedKeyErrorin this race condition.This manifested as a flaky CI failure in
TestContainsOperator.setUpClass→sync_table(IndexedTestModel).Tests
tests/unit/cqlengine/test_management.py) for_get_table_metadataverifying: immediate hit (no refresh), successful retry after refresh, and failure after refresh